Integrating JavaScript using HTML <script> Tag

The HTML <script> tag is used to integrate JavaScript code or give reference through the attribute “src” for external JavaScript files within an HTML document.

With the help of JavaScript, we can dynamically manipulate the HTML elements. Various HTML JavaScript operations can be done including, DOM manipulation, Adding or removing Style to the element, and adding or removing elements from the DOM.

Note: The most common operation done in JavaScript is finding the HTML elements.

Example: Illustration of the basic example of JavaScript that finds the element by tag name and styles the text with green.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>HTML JavaScript</title>
</head>
  
<body>
    <h1>w3wiki</h1>
    <h3>HTML JavaScript</h3>
  
    <script>
        const h1element = document
                          .getElementsByTagName("h1")[0];
        h1element.style.color = "green";
    </script>
</body>
  
</html>


Output

HTML JavaScript

HTML JavaScript is the most popular programming language that helps to add interactivity and provides dynamic behavior. It is known as the client-side scripting language for web pages. JavaScript is used for various purposes, including DOM manipulation, asynchronous requests (AJAX), event handling, fetching external API, and creating interactive web applications.

Additionally, After ES6 JavaScript becomes more popular and provides various functionalities for creating dynamic web pages.

Similar Reads

Integrating JavaScript using HTML